<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Load HTML from a file</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="domdocument.loadhtml.html">« DOMDocument::loadHTML</a></li>
      <li style="float: right;"><a href="domdocument.loadxml.html">DOMDocument::loadXML »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.domdocument.html">DOMDocument</a></li>
    <li>Load HTML from a file</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="domdocument.loadhtmlfile" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DOMDocument::loadHTMLFile</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">DOMDocument::loadHTMLFile</span> &mdash; <span class="dc-title">
   Load HTML from a file
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-domdocument.loadhtmlfile-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>DOMDocument::loadHTMLFile</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$options</code><span class="initializer"> = 0</span></span>): <span class="type"><span class="type"><a href="class.domdocument.html" class="type DOMDocument">DOMDocument</a></span>|<span class="type">bool</span></span></div>

  <p class="para rdfs-comment">
   The function parses the HTML document in the file named
   <code class="parameter">filename</code>. Unlike loading XML, HTML does not have 
   to be  well-formed to load.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-domdocument.loadhtmlfile-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">filename</code></dt>

     <dd>

      <p class="para">
       The path to the HTML file.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">options</code></dt>

     <dd>

      <p class="para">
       Since Libxml 2.6.0, you may also use the
       <code class="parameter">options</code> parameter to specify <a href="libxml.constants.html" class="link">additional Libxml parameters</a>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-domdocument.loadhtmlfile-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。 If called statically, returns a
   <span class="classname"><a href="class.domdocument.html" class="classname">DOMDocument</a></span> 或者在失败时返回 <strong><code>false</code></strong>.
  </p>
 </div>

 <div class="refsect1 errors" id="refsect1-domdocument.loadhtmlfile-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   If an empty string is passed as the <code class="parameter">filename</code>
   or an empty file is named, a warning will be generated. This warning
   is not generated by libxml and cannot be handled using <a href="function.libxml-use-internal-errors.html" class="link">libxml&#039;s error handling
   functions</a>.
  </p>
  <p class="para">在 PHP 8.0.0 之前<em class="emphasis">可以</em>静态调用此方法，但会发出
<strong><code>E_DEPRECATED</code></strong> 错误。自 PHP 8.0.0 起，静态调用此方法会抛出 <span class="classname"><a href="class.error.html" class="classname">Error</a></span> 异常</p>
  <p class="para">尽管非正确格式化的 HTML 仍应该被成功调入，但此函数会在遇到错误标记时产生 <strong><code>E_WARNING</code></strong> 错误。<a href="function.libxml-use-internal-errors.html" class="link">libxml 错误处理函数</a>可以用来处理这类错误。</p>
 </div>

 <div class="refsect1 examples" id="refsect1-domdocument.loadhtmlfile-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5400">
    <p><strong>示例 #1 Creating a Document</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$doc&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">loadHTMLFile</span><span style="color: #007700">(</span><span style="color: #DD0000">"filename.html"</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">saveHTML</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-domdocument.loadhtmlfile-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="domdocument.loadhtml.html" class="methodname" rel="rdfs-seeAlso">DOMDocument::loadHTML()</a> - Load HTML from a string</span></li>
    <li class="member"><span class="methodname"><a href="domdocument.savehtml.html" class="methodname" rel="rdfs-seeAlso">DOMDocument::saveHTML()</a> - Dumps the internal document into a string using HTML formatting</span></li>
    <li class="member"><span class="methodname"><a href="domdocument.savehtmlfile.html" class="methodname" rel="rdfs-seeAlso">DOMDocument::saveHTMLFile()</a> - Dumps the internal document into a file using HTML formatting</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>